package com.ruitu.health_1.mvp.presenter;

import com.ruitu.arad.base.BasePresenter;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.health_1.mvp.model.LoginModel;
import com.ruitu.health_1.ui.LoginActivity;
import com.ruitu.health_1.ui.RegisterActivity;
import com.ruitu.health_1.ui.fragment.MineFragment;
import com.ruitu.router_module.bean.BaseResult2;
import com.ruitu.router_module.bean.user.User;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import okhttp3.RequestBody;

public class LoginPresenter {
    public static class LoginP extends BasePresenter<LoginActivity, LoginModel.LoginM> {
        public Disposable login(RequestBody body) {
            return m.login(body).subscribe(new Consumer<BaseResult2<User>>() {
                @Override
                public void accept(BaseResult2<User> baseResult) throws Exception {
                    v.hideProgress();
                    if (baseResult.isSuccess()) {
                        v.loginSuccess(baseResult.getData());
                    }
                    ToastUtils.showShort(baseResult.getMessage());
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }

        public Disposable loginyan(RequestBody body) {
            return m.loginyan(body).subscribe(new Consumer<BaseResult2<User>>() {
                @Override
                public void accept(BaseResult2<User> baseResult) throws Exception {
                    v.hideProgress();
                    if (baseResult.isSuccess()) {
                        v.loginSuccess(baseResult.getData());
                    }
                    ToastUtils.showShort(baseResult.getMessage());
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                }
            });
        }

        public Disposable doyzm(RequestBody body) {
            return m.doyzm(body).subscribe(new Consumer<BaseResult2>() {
                @Override
                public void accept(BaseResult2 baseResult) throws Exception {
                    v.hideProgress();
                    v.getCodeSuccess();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                }
            });
        }
    }

    public static class RegisterP extends BasePresenter<RegisterActivity, LoginModel.RegisterM> {

        public Disposable register1(RequestBody body) {
            return m.register(body)
                    .subscribe(new Consumer<BaseResult2>() {
                        @Override
                        public void accept(BaseResult2 baseResult2) throws Exception {
                            v.hideProgress();
                            if (baseResult2.isSuccess()) {
                                v.setRegisterSuc();
                            }
                            ToastUtils.showShort(baseResult2.getMessage());
                        }
                    }, new Consumer<Throwable>() {
                        @Override
                        public void accept(Throwable throwable) throws Exception {
                            v.hideProgress();
                        }
                    });
        }

        public Disposable doyzm(RequestBody body) {
            return m.doyzm(body).subscribe(new Consumer<BaseResult2>() {
                @Override
                public void accept(BaseResult2 baseResult) throws Exception {
                    v.hideProgress();
                    if (baseResult.isSuccess()) {
                        v.getCodeSuccess();
                    }
                    ToastUtils.showShort(baseResult.getMessage());
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.getMessage();
                }
            });
        }

    }


}
